package com.semeureka.frame.util;

import javax.xml.bind.DatatypeConverter;

import org.apache.mina.core.buffer.IoBuffer;

public class HexUtils {
	public static String toHex(byte[] val) {
		return DatatypeConverter.printHexBinary(val);
	}

	public static byte[] toBinary(String hexBinary) {
		return DatatypeConverter.parseHexBinary(hexBinary);
	}

	public static int sumupCrc(IoBuffer buffer, int start, int length) {
		byte crc = 0;
		for (int i = 0; i < length; i++) {
			crc += buffer.get(start + i);
		}
		return crc & 0xFF;
	}

	public static int modbusCrc(IoBuffer buffer, int i, int position) {
		// TODO Auto-generated method stub
		return 0;
	}
}
